#ifndef YHAIDA_THREAD_H
#define YHAIDA_THREAD_H
#include "../base/Utils.h"
#include "../mutex/MutexLock.h"
#include "../mutex/Condition.h"
#include "Atomic.h"
#include <memory>
#include <functional>
#include <pthread.h>
#include <iostream>
#include <string>
#include <sys/prctl.h>


namespace yhaida
{
    class Thread : Utils::nocapyable
    {
    public:
        typedef std::function<void()> ThreadFunc;
        explicit Thread(const ThreadFunc ,const std::string name = std::string());
        ~Thread();

        void start();
        void join();

        bool started()
        {
            return _started;
        }
        //统计有多少个线程
        static int numCreated()
        {
            return _numCreated.get();
        }
        pid_t getTid()
        {
            return *_tid;
        }
        const std::string& getThreadName() const
        {
            return _name;
        }
    private:
        bool _started;
        bool _joined;
        //pthread_t是用来create、join和detach等等
        pthread_t _threadId;
        std::shared_ptr<pid_t> _tid;
        ThreadFunc _func;
        std::string _name;
        

        static AtomicInt32 _numCreated;
    };

}

#endif
